using System;
using System.Data;
using System.Net;
using System.Net.Mail;
using System.Text;
namespace HKB.Common
{
	public class Email
	{
		private string ErrMsg = "";
		public bool SendEmail(string smtpserver, string mailuser, string mailpassword, string mailFrom, string mailContent, string mailTo, string mailTitle)
		{
			MailMessage mailMessage = new MailMessage(mailFrom, mailTo);
			mailMessage.BodyEncoding = System.Text.Encoding.Default;
			mailMessage.Subject = mailTitle;
			mailMessage.Body = mailContent;
			mailMessage.Priority = MailPriority.Normal;
			mailMessage.IsBodyHtml = true;
			SmtpClient smtpClient = new SmtpClient(smtpserver);
			smtpClient.UseDefaultCredentials = false;
			smtpClient.Credentials = new NetworkCredential(mailuser, mailpassword);
			smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
			bool result;
			try
			{
				smtpClient.Send(mailMessage);
				mailMessage.Dispose();
				smtpClient.Dispose();
			}
			catch (System.Exception ex)
			{
				this.ErrMsg = ex.Message;
				result = false;
				return result;
			}
			result = true;
			return result;
		}
		public bool SendEmail(DataRow config, string mailContent, string mailTo, string mailTitle)
		{
			string smtpserver = config["MailSmtpServer"].ToString();
			string mailuser = config["MailServerUserName"].ToString();
			string mailpassword = config["MailServerPassWord"].ToString();
			string mailFrom = config["MailServerFrom"].ToString();
			return this.SendEmail(smtpserver, mailuser, mailpassword, mailFrom, mailContent, mailTo, mailTitle);
		}
	}
}
